package com.zhao.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zhao.base.AccessTokenBase;
import com.zhao.model.WeixinOauth2Token;
import com.zhao.util.CommonUtil;

/**
 * 
 * @author zhaowj
 * @date2018年1月23日 下午10:31:10
 */
@WebServlet("/OaAuthServlet")
public class OaAuthServlet extends HttpServlet {
	Logger log=LoggerFactory.getLogger(OaAuthServlet.class);
	private static final long serialVersionUID = 1L;
       
    
    public OaAuthServlet() {
        super();
    }

	 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("gb2312");
		response.setCharacterEncoding("gb2312");
	    
		String state=request.getParameter("state"); 
		
		String code=request.getParameter("code");
         
		if (!"authdeny".equals(code)) {
			WeixinOauth2Token oauthToken=AccessTokenBase.getOauth2AccessToken("wx86b4498a0b1c9e76","c7067c2b1da6bae1064d046325fa1daa",code);
			String openId=oauthToken.getOpenId();
			log.info("用户openId>>"+openId);
		}
	}

	 
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
